Class MockCURLRequest

Summary

Fully Qualified Name: CodeIgniter\Test\Mock\MockCURLRequest
Extends: CURLRequest

Description

Class MockCURLRequest

Simply allows us to not actually call cURL during the test runs. Instead, we can set the desired output and get back the set options.

Methods

Name Description Defined By
__construct() Takes an array of options to set the following possible class properties: CURLRequest
appendBody() Appends data to the body of the current message. Message
appendHeader() Adds an additional header value to any headers that accept multiple values (i.e. are an array or implement ArrayAccess) Message
delete() Convenience method for sending a DELETE request. CURLRequest
fetchGlobal() Fetches one or more items from a global, like cookies, get, post, etc. Request
get() Convenience method for sending a GET request. CURLRequest
getBaseURI() MockCURLRequest
getBody() Returns the Message's body. Message
getDelay() MockCURLRequest
getEnv() Fetch an item from the $_ENV array. Request
getHeader() Returns a single header object. If multiple headers with the same name exist, then will return an array of header objects. Message
getHeaderLine() Retrieves a comma-separated string of the values for a single header. Message
getHeaders() Returns an array containing all headers. Message
getIPAddress() Gets the user's IP address. Request
getMethod() Get the request method. Overrides the Request class' method since users expect a different answer here. CURLRequest
getProtocolVersion() Returns the HTTP Protocol Version. Message
getServer() Fetch an item from the $_SERVER array. Request
hasHeader() Determines whether a header exists. Message
head() Convenience method for sending a HEAD request. CURLRequest
isValidIP() Validate an IP address Request
options() Convenience method for sending an OPTIONS request. CURLRequest
patch() Convenience method for sending a PATCH request. CURLRequest
populateHeaders() Populates the $headers array with any headers the getServer knows about. Message
post() Convenience method for sending a POST request. CURLRequest
prependHeader() Adds an additional header value to any headers that accept multiple values (i.e. are an array or implement ArrayAccess) Message
put() Convenience method for sending a PUT request. CURLRequest
removeHeader() Removes a header from the list of headers we track. Message
request() Sends an HTTP request to the specified $url. If this is a relative URL, it will be merged with $this->baseURI to form a complete URL. CURLRequest
send() Fires the actual cURL request. CURLRequest
setAuth() Set the HTTP Authentication. CURLRequest
setBody() Sets the body of the current message. Message
setForm() Set form data to be sent. CURLRequest
setGlobal() Allows manually setting the value of PHP global, like $_GET, $_POST, etc. Request
setHeader() Sets a header and it's value. Message
setJSON() Set JSON data to be sent. CURLRequest
setMethod() Sets the request method. Used when spoofing the request. Request
setOutput() MockCURLRequest
setProtocolVersion() Sets the HTTP protocol version. Message

Method Details

__construct()

Takes an array of options to set the following possible class properties:

Parameter Name Type Description
$config \App
$uri \URI
$response \ResponseInterface
$options array

Returns:

appendBody()

Appends data to the body of the current message.

Parameter Name Type Description
$data
$data

Returns: \Message|\Response

appendHeader()

Adds an additional header value to any headers that accept multiple values (i.e. are an array or implement ArrayAccess)

Parameter Name Type Description
$name string
$value string

Returns: \Message

delete()

Convenience method for sending a DELETE request.

Parameter Name Type Description
$url string
$options array

Returns: \CodeIgniter\HTTP\ResponseInterface

fetchGlobal()

Fetches one or more items from a global, like cookies, get, post, etc.

Can optionally filter the input when you retrieve it by passing in a filter.

If $type is an array, it must conform to the input allowed by the filter_input_array method.

http://php.net/manual/en/filter.filters.sanitize.php

Parameter Name Type Description
$method string Input
$index string|array|null
$filter int|null Filter
$flags mixed

Returns: mixed

get()

Convenience method for sending a GET request.

Parameter Name Type Description
$url string
$options array

Returns: \CodeIgniter\HTTP\ResponseInterface

getBaseURI()

Returns: void

getBody()

Returns the Message's body.

Returns: mixed

getDelay()

Returns: void

getEnv()

Fetch an item from the $_ENV array.

Parameter Name Type Description
$index null Index
$filter null A
$flags null

Returns: mixed

getHeader()

Returns a single header object. If multiple headers with the same name exist, then will return an array of header objects.

Parameter Name Type Description
$name string

Returns: array|\CodeIgniter\HTTP\Header

getHeaderLine()

Retrieves a comma-separated string of the values for a single header.

This method returns all of the header values of the given case-insensitive header name as a string concatenated together using a comma.

NOTE: Not all header values may be appropriately represented using comma concatenation. For such headers, use getHeader() instead and supply your own delimiter when concatenating.

Parameter Name Type Description
$name string

Returns: string

getHeaders()

Returns an array containing all headers.

Returns: array An array of the request headers

getIPAddress()

Gets the user's IP address.

Returns: string IP address

getMethod()

Get the request method. Overrides the Request class' method since users expect a different answer here.

Parameter Name Type Description
$upper bool Whether

Returns: string

getProtocolVersion()

Returns the HTTP Protocol Version.

Returns: string

getServer()

Fetch an item from the $_SERVER array.

Parameter Name Type Description
$index string|array|null Index
$filter int|null A
$flags null

Returns: mixed

hasHeader()

Determines whether a header exists.

Parameter Name Type Description
$name string

Returns: bool

head()

Convenience method for sending a HEAD request.

Parameter Name Type Description
$url string
$options array

Returns: \ResponseInterface

isValidIP()

Validate an IP address

Parameter Name Type Description
$ip string IP
$which string IP

Returns: bool

options()

Convenience method for sending an OPTIONS request.

Parameter Name Type Description
$url string
$options array

Returns: \CodeIgniter\HTTP\ResponseInterface

patch()

Convenience method for sending a PATCH request.

Parameter Name Type Description
$url string
$options array

Returns: \CodeIgniter\HTTP\ResponseInterface

populateHeaders()

Populates the $headers array with any headers the getServer knows about.

Returns:

post()

Convenience method for sending a POST request.

Parameter Name Type Description
$url string
$options array

Returns: \CodeIgniter\HTTP\ResponseInterface

prependHeader()

Adds an additional header value to any headers that accept multiple values (i.e. are an array or implement ArrayAccess)

Parameter Name Type Description
$name string
$value string

Returns: \Message

put()

Convenience method for sending a PUT request.

Parameter Name Type Description
$url string
$options array

Returns: \CodeIgniter\HTTP\ResponseInterface

removeHeader()

Removes a header from the list of headers we track.

Parameter Name Type Description
$name string

Returns: \Message

request()

Sends an HTTP request to the specified $url. If this is a relative URL, it will be merged with $this->baseURI to form a complete URL.

Parameter Name Type Description
$method
$url string
$options array
$method

Returns: \CodeIgniter\HTTP\ResponseInterface

send()

Fires the actual cURL request.

Parameter Name Type Description
$method string
$url string

Returns: \CodeIgniter\HTTP\ResponseInterface

setAuth()

Set the HTTP Authentication.

Parameter Name Type Description
$username string
$password string
$type string basic

Returns: $this

setBody()

Sets the body of the current message.

Parameter Name Type Description
$data mixed

Returns: \Message|\Response

setForm()

Set form data to be sent.

Parameter Name Type Description
$params array
$multipart bool Set

Returns: $this

setGlobal()

Allows manually setting the value of PHP global, like $_GET, $_POST, etc.

Parameter Name Type Description
$method string
$value
$value

Returns: $this

setHeader()

Sets a header and it's value.

Parameter Name Type Description
$name string
$value array|null|string

Returns: \Message|\Response

setJSON()

Set JSON data to be sent.

Parameter Name Type Description
$data mixed

Returns: $this

setMethod()

Sets the request method. Used when spoofing the request.

Parameter Name Type Description
$method string

Returns: \Request

setOutput()

Parameter Name Type Description
$output

Returns: void

setProtocolVersion()

Sets the HTTP protocol version.

Parameter Name Type Description
$version string

Returns: \Message

Top